package com.tron.dobest.java.tronnio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

public class TronFileChannelCopy {
    public static void main(String[] args) {
        String path = getPath(TronFileChannelCopy.class);
        try (
                final FileInputStream fileInputStream = new FileInputStream(path + "test01.txt");
                final FileOutputStream fileOutputStream = new FileOutputStream(path + "test02.txt");
        ) {
            final FileChannel channel01 = fileInputStream.getChannel();
            final FileChannel channel02 = fileOutputStream.getChannel();
            channel02.transferFrom(channel01, 0, channel01.size());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public static String getPath(Class clazz) {
        String pre = "src/main/java/";
        Package aPackage = clazz.getPackage();
        String name = aPackage.getName();
        String newName = pre + name.replaceAll("\\.", "/") + "/";
        return newName;
    }
}
